import {
  Mesh,
  MeshBasicMaterial,
  Object3D,
  SphereGeometry,
  Sprite,
  SpriteMaterial,
} from "three";
import { livingRoomTexture, tipTexture } from "./TTextures";

import { dataList } from "./data";

export let objectList: Object3D[] = [];
export const tipsSpriteList: Sprite[] = [];

const tipMaterial = new SpriteMaterial({ map: tipTexture, color: 0xffffff });

if (false) {
  //#endregion
} else {
  //#region 球型的方式添加
  const sphereGeometry = new SphereGeometry(16, 50, 50);
  sphereGeometry.scale(16, 16, -16);
  const sphereMaterial = new MeshBasicMaterial({ map: livingRoomTexture });
  const sphere = new Mesh(sphereGeometry, sphereMaterial);
  objectList.push(sphere);

  addTip(dataList.livingRoomTipList);
  //#endregion
}

export function addTip(data: any[]) {
  // 清除掉之前的
  tipsSpriteList.length = 0;
  data.forEach((item) => {
    const tipSprite = new Sprite(tipMaterial);
    tipSprite.scale.set(10, 10, 10);
    tipSprite.position.set(item.position.x, item.position.y, item.position.z);
    (tipSprite as any).content = item.content;
    tipsSpriteList.push(tipSprite);
  });
}
